package main.Q101_200;

import java.util.*;

public class Q171_180 {
    public static void main(String[] args) {
        System.out.println("Question171：Excel表列号");
        System.out.println("Question172：阶乘后的零");
        System.out.println("Question173：二叉搜索树迭代器");
        System.out.println("Question174：");
        System.out.println("Question175：组合两个表(SQL)");
        System.out.println("Question176：第二高的薪水");
        System.out.println("Question177：");
        System.out.println("Question178：分数排名");
        System.out.println("Question179：最大数");
        System.out.println("Question180：");
    }
}

class Question171{
    public int titleToNumber(String columnTitle) {
        char[] col=columnTitle.toCharArray();
        int power=1,result=0;
        for (int i=col.length-1;i>=0;i--){
            result=result+power*(col[i]-64);
            power=power*26;
        }
        return result;
    }
}

class Question172{
    public int trailingZeroes(int n) {
        int count=0;
        for (int i=5;i<=n;i+=5){
            count++;
            int temp=i/5;
            while (temp%5==0){
                count++;
                temp=temp/5;
            }
        }
        return count;
    }
}

class Question173{
    List<Integer> list;//中序遍历序列
    public Question173(TreeNode root) {
        list=new ArrayList<>();
        Stack<TreeNode> stack=new Stack<>();
        while (root!=null||!stack.isEmpty()){
            if (root!=null){
                stack.push(root);
                root=root.left;
            }else {
                root=stack.pop();
                list.add(root.val);
                root=root.right;
            }
        }
    }
    public int next() {
        int next=list.get(0);
        list.remove(0);
        return next;
    }
    public boolean hasNext() {
        return !list.isEmpty();
    }
}

class Question175{
     {
        System.out.println("select FirstName,LastName,City,State \n" +
                "from Person left join Address \n" +
                "on Person.PersonId=Address.PersonId;");
    }
}

class Question176{
    {
        System.out.println("select (\n" +
                "    select distinct salary SecondHighestSalary\n" +
                "    from Employee\n" +
                "    Order By salary Desc\n" +
                "    limit 1 offset 1\n" +
                ") SecondHighestSalary;");
    }
}

class Question178{
    {
        System.out.println("select score, dense_rank() over (order by score desc) as 'rank'\n" +
                "from scores;");
    }
}

class Question179{
    public String largestNumber(int[] nums) {
        StringBuffer max=new StringBuffer();
        int length= nums.length;
        Integer[] sortNums=new Integer[length];
        for (int i=0;i<length;i++){
            sortNums[i]=nums[i];
        }
        Arrays.sort(sortNums, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                long so1=10,so2=10;
                while (so1<=o1) so1*=10;
                while (so2<=o2) so2*=10;
                return (int) (-so2*o1-o2+so1*o2+o1);
            }
        });
        if (sortNums[0]==0) return "0";
        for (int num:sortNums) max.append(num);
        return max.toString();
    }
}